package com.javaclimb.music.controller;

import com.javaclimb.music.exection.BizCodeEnum;
import com.javaclimb.music.service.AdminService;
import com.javaclimb.music.utils.Constant;
import com.javaclimb.music.utils.R;
import com.javaclimb.music.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;

/**
 * @author 夏天
 * @date 2020年11月21日 18:55
 */
@RestController
@RequestMapping("/admin")
@Api(tags = "后台管理接口")
public class AdminController {


    @Autowired
    AdminService adminService;

    @Autowired
    HttpSession session;

    @ApiOperation("后台登录接口")
    @PostMapping("/login/stutas")
    public R loginStutus(@Valid @RequestBody LoginVo loginVo) {
        if (adminService.verifyPassword(loginVo.getName(), loginVo.getPassword())) {
            session.setAttribute(Constant.name, loginVo.getName());
            return R.ok("登录成功");
        }
        return R.error(BizCodeEnum.LOGIN_FAILED);
    }
}
